import {ref} from "vue";

export const useWebsocketInit = (wsUrl) => {
    const ws = ref()
    const msg = ref("")

    function init() {
        ws.value = new WebSocket(wsUrl);
        ws.value.onopen = () => console.log("打开了ws的连接....")
        ws.value.onmessage = e => msg.value = e.data
    }

    return {
        ws,
        msg,
        init,
    }
}